home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-07-03 | 4.1 KB | 130 lines | [TEXT/R*ch] |
- (* test/string.sml
- PS 1994-12-10, 1995-06-14 *)
-
- use "auxil.sml";
-
- local
- open Char String
-
- val s1 = "" (* size s1 = 0 *)
- and s2 = "ABCDE\tFGHI"; (* size s2 = 10 *)
- val ABCDE = List.map chr [65,66,67,68,69];
- in
-
- val test1 = check'(fn _ => (size s1 = 0 andalso size s2 = 10));
- val test2 = check'(fn _ => (sub(s2,6) = chr 70 andalso sub(s2,9) = chr 73));
- val test3 = (sub(s1, 0) seq "WRONG") handle Subscript => "OK" | _ => "WRONG";
- val test4 = (sub(s2, ~1) seq "WRONG") handle Subscript => "OK" | _ => "WRONG";
- val test5 = (sub(s2, 10) seq "WRONG") handle Subscript => "OK" | _ => "WRONG";
-
- val test6 =
- check'(fn _ =>
- "" = concat [] andalso "" = concat [s1]
- andalso s2 = concat [s2] andalso s2^s2 = concat [s2,s2]
- andalso "ABCD" = concat ["A","B","C","D"]);
-
- val test7 = check'(fn _ => "A" = str(chr 65));
-
- val test8 =
- check'(fn _ =>
- "" = implode [] andalso "ABCDE" = implode ABCDE);
-
- val test9 =
- check'(fn _ =>
- [] = explode "" andalso ABCDE = explode "ABCDE");
-
- val test10 =
- check'(fn _ =>
- s1 < s2 andalso s1 <= s1
- andalso s2 > s1 andalso s2 >=s2);
-
- val test11a =
- check'(fn _ =>
- s2 = extract(s2, 0, SOME (size s2))
- andalso s2 = extract(s2, 0, NONE)
- andalso "" = extract(s2, size s2, SOME 0)
- andalso "" = extract(s2, size s2, NONE)
- andalso "" = extract(s1, 0, SOME 0)
- andalso "" = extract(s1, 0, NONE));
-
- val test11b = (extract(s2, ~1, SOME 0) seq "WRONG")
- handle Subscript => "OK" | _ => "WRONG";
- val test11c = (extract(s2, 11, SOME 0) seq "WRONG")
- handle Subscript => "OK" | _ => "WRONG";
- val test11d = (extract(s2, 0, SOME 11) seq "WRONG")
- handle Subscript => "OK" | _ => "WRONG";
- val test11e = (extract(s2, 10, SOME 1) seq "WRONG")
- handle Subscript => "OK" | _ => "WRONG";
- val test11f = (extract(s2, ~1, NONE) seq "WRONG")
- handle Subscript => "OK" | _ => "WRONG";
- val test11g = (extract(s2, 11, NONE) seq "WRONG")
- handle Subscript => "OK" | _ => "WRONG";
-
- val test11h =
- check'(fn _ =>
- "ABCDE" = extract(s2, 0, SOME 5)
- andalso "FGHI" = extract(s2, 6, SOME 4)
- andalso "FGHI" = extract(s2, 6, NONE));
-
- val test12a =
- check'(fn _ =>
- s2 = substring(s2, 0, size s2)
- andalso "" = substring(s2, size s2, 0)
- andalso "" = substring(s1, 0, 0));
-
- val test12b = (substring(s2, ~1, 0) seq "WRONG")
- handle Subscript => "OK" | _ => "WRONG";
- val test12c = (substring(s2, 11, 0) seq "WRONG")
- handle Subscript => "OK" | _ => "WRONG";
- val test12d = (substring(s2, 0, 11) seq "WRONG")
- handle Subscript => "OK" | _ => "WRONG";
- val test12e = (substring(s2, 10, 1) seq "WRONG")
- handle Subscript => "OK" | _ => "WRONG";
-
- val test12f =
- check'(fn _ =>
- "ABCDE" = substring(s2, 0, 5)
- andalso "FGHI" = substring(s2, 6, 4));
-
- val test13a =
- check'(fn _ =>
- (translate (fn _ => "") s2 = ""
- andalso translate (fn x => str x) "" = ""
- andalso translate (fn x => str x) s2 = s2));
-
- val test13b =
- check'(fn _ =>
- (translate (fn c => if c = #"\t" then "XYZ " else str c) s2
- = "ABCDEXYZ FGHI"));
-
- val test14 =
- check'(fn _ =>
- (tokens isSpace "" = []
- andalso tokens isSpace " \t \n" = []
- andalso tokens (fn c => c = #",") ",asd,,def,fgh"
- = ["asd","def","fgh"]));
-
- val test15 =
- check'(fn _ =>
- (fields isSpace "" = [""]
- andalso fields isSpace " \t \n" = ["","","","","","",""]
- andalso fields (fn c => c = #",") ",asd,,def,fgh"
- = ["","asd","","def","fgh"]));
-
- val test16a =
- check'(fn _ =>
- EQUAL = compare(s1,s1) andalso EQUAL = compare(s2,s2)
- andalso LESS = compare("A", "B")
- andalso GREATER = compare("B", "A")
- andalso LESS = compare("ABCD", "ABCDE")
- andalso GREATER = compare("ABCDE", "ABCD"));
-
- val test16b =
- check'(fn _ =>
- EQUAL = compare(s1,s1) andalso EQUAL = compare(s2,s2)
- andalso LESS = compare("A", "a")
- andalso GREATER = compare("b", "B")
- andalso LESS = compare("abcd", "abcde")
- andalso GREATER = compare("abcde", "abcd"));
- end
-